<link rel="stylesheet" type="text/css" href="css/fitem.css">
<script type="text/javascript">
    var url;
    function newWO(){
        $('#dlgWO').dialog('open').dialog('setTitle','WO Baru');
        $('#fmWO').form('clear');
        url = 'pages/wo/wo_new.php';
    }
    function editWO(){
        var row = $('#dgWO').datagrid('getSelected');
        if (row){
            $('#dlgWO').dialog('open').dialog('setTitle','Edit WO');
            $('#fmWO').form('load',row);
            url = 'pages/wo/wo_update.php?id='+row.idWO;
        }
    }
    function saveWO(){
        $('#fmWO').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                if (result.success){
                    $('#dlgWO').dialog('close');		// close the dialog
                    $('#dgWO').datagrid('reload');	// reload the user data
                    $.messager.show({
                        title: 'Sukses',
                        msg: result.msg
                    });
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: result.msg
                    });
                }
            }
        });
    }
    function removeWO(){
        var row = $('#dgWO').datagrid('getSelected');
        if (row){
            $.messager.confirm('Confirm','Are you sure you want to remove this wo?',function(r){
                if (r){
                    $.post('pages/wo/wo_remove.php',{id:row.idWO},function(result){
                        if (result.success){
                            $('#dgWO').datagrid('reload');	// reload the user data
                        } else {
                            $.messager.show({	// show error message
                                title: 'Error',
                                msg: result.msg
                            });
                        }
                    },'json');
                }
            });
        }
    }

    function doSearchDataWO() 
    {
        var postThis = $('#fcariWO').serialize();
        $('#dgWO').datagrid('reload',{
            ref:postThis
        });
    }


</script>

<table id="dgWO" title="Daftar WO" class="easyui-datagrid"
       url="pages/wo/wo_getdata.php"
       toolbar="#toolbarWO" pagination="true"
       rownumbers="true" singleSelect="true" fitColumns="true">
    <thead>
        <tr>
            <th field="namaCustomer" width="50">Work Order</th>
            <th field="namaCustomer" width="50">Date Created</th>
            <th field="namaCustomer" width="50">Date Requested</th>

            <th field="namaCustomer" width="50">Customer</th>
            <th field="alamatCustomer" width="50">Address</th>
            <th field="attnCustomer" width="50">Contact Person</th>
            <th field="telpCustomer" width="50">Telp.</th>
            <th field="faxCustomer" width="50">Fax</th>

            <th field="keterangan" width="50">Scope Of Work</th>
            <th field="keterangan" width="50">Note</th>

            <th field="namaCustomer" width="50">Job No</th>
            <th field="keterangan" width="50">Job Requested</th>
            <th field="keterangan" width="50">Job Status</th>
            <th field="keterangan" width="50">Job Start Date</th>
            <th field="keterangan" width="50">Job End Date</th>

            <th field="keterangan" width="50">Unit Type</th>
            <th field="keterangan" width="50">M/N</th>
            <th field="keterangan" width="50">S/N</th>
            <th field="keterangan" width="50">Engineer in Charge</th>
            <th field="keterangan" width="50">Approved By</th>
        </tr>
    </thead>
</table>
<div id="toolbarWO" style='padding:10px;height:auto'>
    <form id='fcariWO'>	
        Nama Customer: 
        <input class='easyui-validatebox' type='text' name='filternamaCustomer' id='wofilternamacustomer'>
        Alamat Customer: 
        <input class='easyui-validatebox' type='text' name='filteralamatCustomer' id='wofilteralamatcustomer'>
        Attn Customer: 
        <input class='easyui-validatebox' type='text' name='filterattnCustomer' id='wofilterattncustomer'>
        Job Status: 
        <input class='easyui-validatebox' type='text' name='filterJobStatus' id='wofilterjobstatus'>
        <a href='javascript:void(0)' class='easyui-linkbutton' iconCls='icon-search' onclick='doSearchDataWO()'>Cari Data</a>
    </form>
    <br>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" onclick="newWO()">New</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" onclick="editWO()">Edit</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" onclick="removeWO()">Remove</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-print" onclick="printWO()">Print</a>
</div>

<div id="dlgWO" class="easyui-dialog" style="width:800px;height:auto;padding:10px;" closed="true" modal="true">
    <form id="fmWO" method="post">
        <div  class="fitem">
            <label>Nama Customer</label>
            <input class="easyui-validatebox" type="text" style="width:280px" name="namaCustomer" id="namaCustomer" required >
        </div>
        <div  class="fitem">
            <label>Alamat</label>
            <input class="easyui-validatebox" style="width:520px" name="alamatCustomer" required >
        </div>
        <div  class="fitem">
            <label>Attn</label>
            <input class="easyui-validatebox" style="width:280px" name="attnCustomer" required >
        </div>
        <div  class="fitem">
            <label>Telp</label>
            <input class="easyui-validatebox" style="width:180px" name="telpCustomer"><br>
        </div>
        <div  class="fitem">
            <label>Fax</label>
            <input class="easyui-validatebox" style="width:180px" name="faxCustomer"><br>
        </div>
        <div  class="fitem">
            <label>Keterangan</label>
            <textarea class="easyui-validatebox" name="keterangan" style="height:90px;width:520px"></textarea>
        </div>
        <div  class="fitem">
            <label></label><a href="#" class="easyui-linkbutton" onclick="saveWO()">Save</a>
        </div>
    </form>
</div>
